// pages/searchGoodsList/searchGoodsList.js
const {
  getSearchGoodsList, //搜索
  getNewSorting //排序
} = require('../../http/api')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keyword:'',
    goodsList:[],
    name:'',
    flag:false,
    // list:[]
  },
  async searchs(e){
    const list = wx.getStorageSync('infor')
    // console.log(this.data.list);
    list.unshift(e.detail.value)
    wx.setStorageSync('infor', list)
    this.setData({
      keyword:e.detail.value
    })
    const res1 = await getNewSorting({infor:this.data.keyword,orderBy:this.data.name})
    // console.log(res1);
    this.setData({
      goodsList:res1.data.result
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    this.setData({
      keyword:options.orderBy
    })
  },
  async sort(e){
    // console.log(e.currentTarget.dataset.name);
    this.setData({
      name:e.currentTarget.dataset.name
    })
    const res1 = await getNewSorting({infor:this.data.keyword,orderBy:this.data.name})
    // console.log(res1);
    this.setData({
      goodsList:res1.data.result
    })
  },
  toggle(){
    this.setData({
      flag:!this.data.flag
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  async onShow() {
    const res = await getSearchGoodsList(this.data.keyword)
    console.log(res);
    // console.log(this.data.keyword);
    this.setData({
      goodsList:res.data.result
    })
    // 新品排序
    console.log(this.data.keyword);
    const res1 = await getNewSorting({infor:this.data.keyword,orderBy:this.data.name})
    console.log(res1);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})